package cn.hairui.blog.repository;

import cn.hairui.blog.mapper.TopicMapper;
import cn.hairui.blog.model.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 21:25
 */
@Repository
public class TopicRepository {

    @Autowired
    private TopicMapper topicMapper;

    public List<Topic> findLimited(int count) {
        return topicMapper.findLimited(count);
    }

    public List<Topic> list() {
        return topicMapper.list();
    }

    public Topic find(int id) {
        return topicMapper.selectByPrimaryKey(id);
    }

    public List<Map> listMgr() {
        return topicMapper.listMgr();
    }

    public int add(Topic topic) {
        topicMapper.insert(topic);
        return topic.getId();
    }

    public void update(Topic topic) {
        topicMapper.updateByPrimaryKey(topic);
    }

    public void delete(int id) {
        topicMapper.deleteByPrimaryKey(id);
    }

    public List<Map> findCountList() {
        return topicMapper.findCountList();
    }
}
